export default {
	data () {
		return {
			passShow: true,
			remember: false,
			phone:'',
			codeMsg:'获取验证码',
			showModal:false,
			showContent:'',
			isSend:false,
			code:'',
			password:''
		}
	},
	methods:{
		// 验证手机号
		verifyMobile(){
			//手机正则表达式
			let phoneCode = /^1[3456789]\d{9}$/
			if(this.phone){
				this.$api.verifyMobile(this.phone).then((res)=>{
					if(res.data.returnCode == 601) {
						this.showModal = true
						this.showContent = res.data.message;
					}
				})
			}else if(!(phoneCode.test(this.phone))) {
				this.showModal = true
				this.showContent = '请输入正确的手机号码'
				return;
			}
		},
		codeBlur() {
			if (this.code == '') {
				this.showModal = true
				this.showContent = '验证码不能为空'
				return;
			}
		},
		passwordBlur() {
			//密码正则表达式
			let passCode = /(?!.*\s)(?!^[\u4E00-\u9FA5]+$)(?!^[a-zA-Z]+$)(?!^[\d]+$)(?!^[^\u4E00-\u9FA5a-zA-Z\d]+$)^.{6,20}$/
			if (!(passCode.test(this.password))) {
				this.showModal = true
				this.showContent = '密码不少于6位数，且字母、数字和符号至少包含两种。'
				return;
			}
		},
		// 发送验证码
		sendCode() {
			let _this = this
			if(_this.isSend){
				return;
			}
			//手机正则表达式
			let phoneCode = /^1[3456789]\d{9}$/
			if(_this.phone == '' || !(phoneCode.test(this.phone))){
				_this.showModal = true
				_this.showContent = '请输入正确的手机号码'
				return;
			}
			_this.$api.sedNote(_this.phone,'Register').then((res)=>{
				if (!_this.timer) {
					_this.count = 60;
					_this.isSend = true;
					_this.timer = setInterval(() => {
						if (_this.count > 0 && _this.count <= 60) {
							_this.codeMsg = _this.count+'s'
							_this.count--;
						} else {
							_this.codeMsg = '获取验证码'
							clearInterval(_this.timer);
							_this.isSend = false;
							_this.timer = null;
						}
					}, 1000)
				}
			})
		},
		// 注册
		register(){
			let _this = this
			let phoneCode = /^1[3456789]\d{9}$/
			//密码正则表达式
			let passCode = /(?!.*\s)(?!^[\u4E00-\u9FA5]+$)(?!^[a-zA-Z]+$)(?!^[\d]+$)(?!^[^\u4E00-\u9FA5a-zA-Z\d]+$)^.{6,20}$/
			if (!(phoneCode.test(_this.phone))) {
				_this.showModal = true
				_this.showContent = '请输入正确的手机号码'
				return;
			}
			if (_this.code == '') {
				_this.showModal = true
				_this.showContent = '验证码不能为空'
				return;
			}
			if (!(passCode.test(_this.password))) {
				_this.showModal = true
				_this.showContent = '密码不少于6位数，且字母、数字和符号至少包含两种。'
				return;
			}
			if(_this.remember == false) {
				_this.showModal = true
				_this.showContent = '请勾选同意和雅医策《用户服务协议》《隐私政策》'
				return;
			}

			_this.$api.register({code:_this.code,password:_this.password,phone:_this.phone}).then((res)=>{
				if(res.data.returnCode == 200){
					localStorage.setItem('token',res.data.result.token)
					uni.navigateTo({
						url:'/pages/login/certification'
					})
				}
			})
		},
	}
}